package com.newtype.meeting.server;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.extjs.gxt.ui.client.Registry;
import com.newtype.meeting.client.GMeeting;
import com.newtype.meeting.shared.AccountDTO;
import com.newtype.meeting.shared.LoginInfo;

public class SendEmailToAccount {

	/**
	 * 给员工发送信息
	 * @param email
	 */
	protected void sendEmailToAccount(AccountDTO account) {
		LoginInfo loginInfo=Registry.get(GMeeting.LOGININFO);
		
		Properties props=new Properties();
		Session session=Session.getDefaultInstance(props,null);
		
		String msgBody="你的会议功能帐号已开通，请登录是使用";
		try{
			 Message msg = new MimeMessage(session);             
			 msg.setFrom(new InternetAddress(loginInfo.getEmailAddress()));             
			 msg.addRecipient(Message.RecipientType.TO,                              
					 new InternetAddress(account.getEmail(), account.getFullName()));             
			 msg.setSubject("Your Example.com account has been activated");            
			 msg.setText(msgBody);             
			 Transport.send(msg); 
		}catch (AddressException e) {            
			// ...         
		} catch (MessagingException e) {             
				// ...         
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
}
